package com.zpf.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * projectName:2022ZPF
 * author:
 * time:2022/4/19 0:01
 * description:
 */
@WebServlet("/testServlet")
public class TestServlet extends BaseServlet {

    public void select(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse resp){
        System.out.println("add");
        try {
            resp.getWriter().print("ajax");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public String add(HttpServletRequest request, HttpServletResponse response){
        System.out.println("add");
        return "redirect:/login.jsp";//重定向
    }

    public String update(HttpServletRequest request, HttpServletResponse response){
        System.out.println("update");
        return "forward:/login.jsp";//请求转发
    }


//    @Override
//    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        doPost(request,response);
//    }
//
//    @Override
//    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String id = request.getParameter("id");
//        System.out.println(id);
//
//        //响应前端（转发重定向）(幂等性问题)
//      //  response.sendRedirect("/login.jsp");
//        //request.getRequestDispatcher("/login.jsp").forward(request,response);
//
//        //如果前端是AJAX
//        response.setCharacterEncoding("UTF-8");
//        response.setContentType("text/html;charset=UTF-8");
//        response.getWriter().print("这是我的仿小米商城");
//    }
}